from abc import ABC, abstractmethod
from typing import Dict, Any

# 全局注册表
HANDLER_REGISTRY = {}

def register_handler(condition_type: str):
    """装饰器：自动注册 handler 到全局字典"""
    def decorator(cls):
        if condition_type in HANDLER_REGISTRY:
            raise ValueError(f"Handler for '{condition_type}' already exists!")
        HANDLER_REGISTRY[condition_type] = cls()
        return cls
    return decorator

class PermissionRuleHandler(ABC):
    @abstractmethod
    def get_required_config_keys(self) -> list:
        pass

    @abstractmethod
    def validate_config(self, config: Dict[str, Any]) -> bool:
        pass

    @abstractmethod
    def generate_sql(self, table_alias: str, config: Dict[str, Any], user: dict) -> str:
        pass